public class DuoTaiDemo21 {
    public static void main(String[] args) {
        // 父类引用 指向子类对象
        Animal2 animal2 = new Cat2("小猫");

        // 向上转型 子转父
        Cat2 cat2 = new Cat2("小猫咪");
        Animal2 animal21 = cat2;
        // 向下转型  父转子 强制转换

        
        Animal2 animal22 = new Dog2("小狗");
        Dog2 dog2 = (Dog2) animal22;


        Animal2 animal23 = new Cat2("小猫1");
        if (animal23 instanceof Dog2) {// 判断一下在运行的时候到底是谁产生的实例
            Dog2 dog = (Dog2) animal23;
        }


    }
}


class Animal2 {
    private String name;

    public Animal2(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void eat() {
        System.out.println("吃面条");
    }
}

class Cat2 extends Animal2 {


    public Cat2(String name) {
        super(name);
    }

    @Override
    public void eat() {
        System.out.println("吃面包");
    }

    public void music() {
        System.out.println("听音乐");
    }
}

class Dog2 extends Animal2 {
    public Dog2(String name) {
        super(name);
    }
}
